﻿#region

using System.Linq;
using Styx;
using Styx.WoWInternals;
using Styx.WoWInternals.WoWObjects;

#endregion

namespace Ink_Master.Bots.InkMaster.BagHandlers
{
    public class Sorting
    {
        /// <summary>
        ///   Sorts the bags.
        /// </summary>
        public static void SortBags()
        {
            foreach (WoWItem item in StyxWoW.Me.BagItems.Where(item => item.IsMillable && item.StackCount != 20))
            {
                //pick up a partial stack or single item, hit the macro and it will combine with other partial stacks
                item.PickUp();
                Lua.DoString(
                    @"/run local t,x,c=GetCursorInfo()if t=='item'then for i=0,4 do for j=1,28 do _,c,t=GetContainerItemInfo(i,j)if c and c>0 and c<select(8,GetItemInfo(x))and not t and strmatch(GetContainerItemLink(i,j)or'','m:'..x)then PickupContainerItem(i,j)end end end end");
            }
        }
    }
}